-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-137576: Fix for Basic REPL Showing Incorrect Code in Tracebacks with PYTHONSTARTUP #137625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
My original patch here also caused the tracebacks to report the filename as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
A couple of nits.
Misc/NEWS.d/next/Core_and_Builtins/2025-08-10-21-34-12.gh-issue-137576.0ZicS-.rst
Outdated
Show resolved
Hide resolved
if (len >= 2 | ||
&& PyUnicode_ReadChar(filename, 0) == '<' | ||
&& PyUnicode_ReadChar(filename, len - 1) == '>') { | ||
PyObject *middle = PyUnicode_Substring(filename, 1, len-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add error checks for PyUnicode_Substring
, since it could return NULL
?
If that happens, simply return NULL
.
Also, in run_mode
, please add an error check for when get_interactive_filename
returns NULL
(just propagate that NULL
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review!
Could you please add error checks for
PyUnicode_Substring
, since it could returnNULL
?
Yep, I added a check there.
Also, in
run_mode
, please add an error check for whenget_interactive_filename
returnsNULL
(just propagate thatNULL
).
I think this one is already handled, on lines 1406-1408 (which happen just after get_interactive_filename
is called).
if (interactive_filename == NULL) {
return NULL;
}
Co-authored-by: Kirill Podoprigora <[email protected]>
This patch attempts to fix #137576 by changing the way
interactive_filename
is computed for the basic REPL to make sure that it always begins with<
and ends with>
so that doesn't get an entry inlinecache.cache
(which was causing the source fromPYTHONSTARTUP
to be used instead of the interactive input when generating tracebacks).Updated behavior: